package org.example.petitionplatformsystem.service.Impl;

import org.example.petitionplatformsystem.dao.KnowledgeBaseRepository;
import org.example.petitionplatformsystem.dao.model.KnowledgeBase;
import org.example.petitionplatformsystem.service.KnowledgeBaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class KnowledgeBaseServiceImpl implements KnowledgeBaseService {
    @Autowired
    private KnowledgeBaseRepository knowledgeBaseRepository;

    @Override
    public void addKnowledgeBase(KnowledgeBase knowledgeBase) {
        knowledgeBaseRepository.save(knowledgeBase);
    }

    @Override
    public void updateKnowledgeBase(KnowledgeBase knowledgeBase) {
        knowledgeBaseRepository.save(knowledgeBase);
    }

    @Override
    public void deleteKnowledgeBase(KnowledgeBase knowledgeBase) {
        knowledgeBaseRepository.delete(knowledgeBase);
    }

    @Override
    public KnowledgeBase getKnowledgeBaseById(long id) {
        return knowledgeBaseRepository.findById(id).orElse(null);
    }

    @Override
    public List<KnowledgeBase> getAllKnowledgeBases() {
        return knowledgeBaseRepository.findAll();
    }
}
